/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package config;

import Data.FileProcess;
import decode.crypto;
/**
 * Obtiene los valores de conexion a la Base de Datos
 * valores encriptados en el archivo config.ini
 * @author Administrador
* Patron de Diseño Singleton
 */
public class dataServer {
    private static dataServer INSTANCE = null;
    private String host;
    private String port;
    private String user;
    private String pass;
    private String dbname;
    private String dbclass;
    private String dbmanager;
    private String sURL;
    /**
     * Constructor privado para el singleton
     */
    public String getUser(){return user;}
    public String getPass(){return pass;}
    public String getDBClass(){return dbclass;}
    
    public void setHost(String shost){host=shost;}
    public void setDBName(String db){dbname=db;}
    public void setUser(String suser){user=suser;}
    public void setPass(String spass){pass=spass;}
    
    
    public void createURL(){
    	sURL="";
        sURL="jdbc:"+dbmanager+"://"+host;
        if (port==null || port.isEmpty()) {
            sURL=sURL+"";
        }
        else {sURL=sURL+":"+port;}
        sURL=sURL+"/"+dbname;
    }
    
    dataServer(){
        //FileProcess f = new FileProcess("config.ini","r");
        //Object [] data = f.read();
        //crypto cr = new crypto();
        //cr.StringEncrypter("siam_siar");
        //System.out.println("Primero->"+cr.decrypt(data[0].toString()));
        /*host=cr.decrypt(data[0].toString());
        port=cr.decrypt(data[1].toString());
        user=cr.decrypt(data[2].toString());
        pass=cr.decrypt(data[3].toString());
        //System.out.println("pass"+pass);
        dbname=cr.decrypt(data[4].toString());
        dbclass=cr.decrypt(data[5].toString());
        dbmanager=cr.decrypt(data[6].toString());
         
         */
        host="localhost";
        port="5432";
        user="postgres";
        pass="12345";
        //System.out.println("pass"+pass);
        dbname="academico";
        dbclass="org.postgresql.Driver";
        dbmanager="postgresql";
        createURL();
    }
    /**
     * Obtiene la URL de conexion a la Base de datos
     * @return
     * URL de conexion
     */
    @SuppressWarnings("empty-statement")
    public String getServerURL(){
        return sURL;
    }
    /**
     * Crea una Instancia de la clase:Singleton
     */
    private synchronized static void createInstance() {
        if (INSTANCE == null) {
            INSTANCE = new dataServer();
        }
    }
    /**
     * Constructor del Singleton
     * @return
     * Retorna la instancia creada de la clase
     */
    public static dataServer getInstance() {
        if (INSTANCE == null) createInstance();
        return INSTANCE;
    }
}
